import json
import pandas as pd

path = [
    "./data/api_nodes_estimator.csv",
    "./data/m-a_edges.csv",
    "./data/mashup_nodes_estimator.csv",
    "./data/split_nodes.csv",
    "./data/tranfer_nodes.csv",
]

df1 = pd.read_csv(path[2], sep="\t")  # m
df0 = pd.read_csv(path[1], sep="\t")  # m-a
df2 = pd.read_csv(path[0], sep="\t")  # a
df1 = df1[["name", "c"]]
df2 = df2[["url", "c"]]
df4 = pd.merge(df0, df2, left_on="target", right_on="url", how="inner")
df5 = pd.merge(df4, df1, left_on="source", right_on="name", how="inner")
df5.drop(["name", "url"], axis=1, inplace=True)
df5.rename(columns={"c_x": "t", "c_y": "c"}, inplace=True)
df5.to_csv("./output/2-1m-a-c-t表.csv", index=0)
df6 = df5[df5["t"] == df5["c"]]
df6.sort_values(by=["c", "source"], ascending=[False, True], inplace=True)
df6.index = range(len(df6))
df6.to_csv("./output/2-2category和tags相同表.csv", index=0)
print(df6)


